package com.sys.midware.hbase.hcore.Optimize;

import java.util.Set;

import com.sys.midware.hbase.config.BHBaseConfig;
import com.sys.midware.hbase.config.BHBaseConfigHolder;

/**
 * Hbase 创建表的信息和表优化参数
 * 
 * @author peter.pan
 *
 */
public class TableOptimize {

    // 表优化参数
    private String tableName;

    private boolean isCompactionEnabled = false;

    private boolean autoFlushTo = true;// 数据入库之前先设置此项为false;入库完成后，手动刷入数据

    private Set<ColumnFamilyOptimize> columnFamilys;

    private long writeBufferSize = -1;// unit Mbytes

    private OprimzeParam.WAL wal;// 设置WAL的类型

    private QueryOptimze queryOptimze = null;
    
    private BHBaseConfig BhbaseConfig;

    public TableOptimize(String tableName, boolean isCompactionEnabled, boolean autoFlushTo,
            Set<ColumnFamilyOptimize> columnFamilys, long writeBufferSize, OprimzeParam.WAL wal,
            QueryOptimze queryOptimze) {
        super();
        this.tableName = tableName;
        this.isCompactionEnabled = isCompactionEnabled;
        this.autoFlushTo = autoFlushTo;
        this.columnFamilys = columnFamilys;
        this.writeBufferSize = writeBufferSize;
        this.wal = wal;
        this.queryOptimze = queryOptimze;
    }

    /**
     * isCompactionEnabled true autoFlushTo false writeBufferSize 5M
     * WAL.SKIP_WAL QueryOptimze default
     * 
     * @param tableName
     * @param columnFamilys
     */
    public TableOptimize(String tableName, Set<ColumnFamilyOptimize> columnFamilys) {
        BhbaseConfig = BHBaseConfigHolder.get();
        this.tableName = tableName;
        this.columnFamilys = columnFamilys;
        this.isCompactionEnabled = BhbaseConfig.isHbaseCompaction();
        this.writeBufferSize = BhbaseConfig.getHbaseWriteBuffer();
        this.autoFlushTo = BhbaseConfig.isHbaseAutoflush();
        this.queryOptimze = new QueryOptimze();
        this.wal = Enum.valueOf(OprimzeParam.WAL.class, BhbaseConfig.getHbaseWal());
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public boolean isCompactionEnabled() {
        return isCompactionEnabled;
    }

    public void setCompactionEnabled(boolean isCompactionEnabled) {
        this.isCompactionEnabled = isCompactionEnabled;
    }

    public boolean isAutoFlushTo() {
        return autoFlushTo;
    }

    public void setAutoFlushTo(boolean autoFlushTo) {
        this.autoFlushTo = autoFlushTo;
    }

    public Set<ColumnFamilyOptimize> getColumnFamilys() {
        return columnFamilys;
    }

    public void setColumnFamilys(Set<ColumnFamilyOptimize> columnFamilys) {
        this.columnFamilys = columnFamilys;
    }

    public long getWriteBufferSize() {
        return writeBufferSize;
    }

    public void setWriteBufferSize(long writeBufferSize) {
        this.writeBufferSize = writeBufferSize;
    }

    public OprimzeParam.WAL getWal() {
        return wal;
    }

    public void setWal(OprimzeParam.WAL wal) {
        this.wal = wal;
    }

    public QueryOptimze getQueryOptimze() {
        return queryOptimze;
    }

    public void setQueryOptimze(QueryOptimze queryOptimze) {
        this.queryOptimze = queryOptimze;
    }

}
